/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.Division;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author owtee
 */
@Stateless
public class DivisionFacade extends AbstractFacade<Division> {

    @PersistenceContext(unitName = "MSGPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DivisionFacade() {
        super(Division.class);
    }

    public List<Division> findByComId(List<Integer> comId) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT d FROM Division d WHERE d.comId.comId IN :comId")
                .setParameter("comId", comId)
                .getResultList();
    }

    public List<Division> findByComId(int start, int end, List<Integer> comId) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT d FROM Division d WHERE d.comId.comId IN :comId")
                .setFirstResult(start)
                .setMaxResults(end)
                .setParameter("comId", comId)
                .getResultList();
    }
}
